#ifndef ntmy_config_h
#define ntmy_config_h

#include <fstream>

#include "json/json.h"

class NtmyConfig {
public:
	NtmyConfig(const std::string &str = "config.json") {
		std::ifstream ifs(str.c_str());

		Json::Reader reader;
		reader.parse(ifs, root_);
	}
	NtmyConfig(const NtmyConfig &) = delete;
	NtmyConfig &operator=(const NtmyConfig &) = delete;
	NtmyConfig(NtmyConfig &&) = delete;
	NtmyConfig &operator=(NtmyConfig &&) = delete;

	
	double GetConfig(const std::string &str) const {
		return GetConfig(root_, str, 0).asDouble();
	}

private:
	Json::Value GetConfig(const Json::Value val, const std::string &str, int start) const {
		int end = start;
		while (end < str.size() && str[end] != '.')
			++end;
		std::string subst = str.substr(start, end - start);
		if (end == str.size())
			return val[subst];
		return GetConfig(val[subst], str, end + 1);
	}
private:
	Json::Value root_;
};

#endif